<?php

/*
 * 2021/7/16
 * 8:59
 * User: 2650332702@qq.com
 */
namespace App\Api\Repositories;
use App\Api\Models\Comments;
use App\Api\Models\Goods;
use App\Api\Models\GoodsComments;
use App\Api\Models\Seckill;
use Illuminate\Http\Request;

class SeckillRepositorie
{
    //获得商品数据
    //秒杀商品ID
    static public function OnceSeckill($id,$allow_field = null)
    {
        $good_id = Seckill::skInGood($id,'good_id');
        //获取商品信息
        $data = Goods::OnceGood($good_id,$allow_field);
        $data['goods_image'] = config('aliyun.cui').$data['goods_image'];
        $data['discounted_price'] = Seckill::skInGood($id,'price');
        $data['end_time'] = date('Y-m-d H:i:s',Seckill::skInGood($id,'end_time'));
        return $data;
    }
    //获得评论
    static public function getComments($good_id)
    {
        $comment = [];
        $array_cid = GoodsComments::allComments($good_id);
        foreach ($array_cid as $item){
            $comment[] = Comments::getAllComment($item['comment_id']);
        }
        foreach ($comment as &$v){
            $v['goods_image'] = config('aliyun.cui').$v['goods_image'];
            $v['avatar'] = config('aliyun.cui').$v['avatar'];
            if($v['detail_content']==1){
                $video[] = $v;
            }else{
                $pictures[] =$v;
            }
        }
        return [
            'all'=>$comment,
            'video'=>['data'=>$video,'count'=>count($video)],
            'pictures'=>['data'=>$pictures,'count'=>count($pictures)]
        ];
    }

}
